babl: add handling of BABL_RGB_OVERRIDE environment variable
authorØyvind Kolås <pippin@gimp.org>
Sat, 19 Aug 2017 01:53:57 +0000 (03:53 +0200)
committerØyvind Kolås <pippin@gimp.org>
Sat, 19 Aug 2017 01:53:57 +0000 (03:53 +0200)
babl/babl-space.c
babl/babl.h

index e6ef5ed860ec2f57c8dd0fd6b91f0dd8d13fb9d1..37c40ade9c04a5a5925bc8de020d4aeec2e42642 100644 (file)
@@ -213,23 +213,42 @@ babl_space_class_for_each (BablEachFunction each_fun,
 void
 babl_space_class_init (void)
 {
-  /* we register sRGB first so that lookups for it is fastest */
-#ifdef CCE
-  babl_space_rgb_chromaticities ("sRGB",
-                  0.3127, 0.3290, /* D65 */
+  if (getenv ("BABL_RGB_OVERRIDE"))
+  {
+     /* added to be able to easily have the behavior of Elle Stones CCH fork of babl,
+      * configuring the working space through an environment variable should be easier
+      * than keeping compiled versions of CCH GIMP for different spaces.
+      */
+
+     char *override = getenv ("BABL_RGB_OVERRIDE");
+     if (strlen (override) < 5)
+       {
+          babl_space_rgb_chromaticities ("sRGB",
+                  0.3127,  0.3290, /* D65 */
                   0.6400,  0.3300,
                   0.3000,  0.6000,
                   0.1500,  0.0600,
                   babl_trc("linear"), NULL, NULL);
-#else
-  babl_space_rgb_chromaticities ("sRGB",
+       }
+     else
+     {
+       float xr=0.6400, yr=0.3300, xg=0.3000,  yg=0.6000,  xb=0.1500, yb=0.0600, wx=0.3127, wy=0.3290, gamma=2.2;
+       sscanf (override, "%f %f %f %f %f %f %f %f %f", &xr, &yr, &xg, &yg, &xb, &yb, &wx, &wy, &gamma);
+       fprintf (stderr, "overriding babl default RGB space with: r=%f %f g=%f %f b=%f %f w=%f %f gamma=%f\n",
+                xr, yr, xg, yg, xb, yb, wx, wy, gamma);
+       babl_space_rgb_chromaticities ("sRGB",
+            wx, wy, xr, yr, xg, yg, xb, yb, babl_trc_gamma (gamma), NULL, NULL);
+     }
+  }
+  else
+  {
+     babl_space_rgb_chromaticities ("sRGB",
                   0.3127,  0.3290, /* D65 */
-                  //0.3127, 0.3290, /* D65 */
                   0.6400,  0.3300,
                   0.3000,  0.6000,
                   0.1500,  0.0600,
                   babl_trc("sRGB"), NULL, NULL);
-#endif
+  }
 
   babl_space_rgb_chromaticities (
       "Adobe",
@@ -330,7 +349,7 @@ void babl_space_from_xyz (const Babl *space, const double *xyz, double *rgb)
   _babl_space_from_xyz (space, xyz, rgb);
 }
 
-double * babl_space_get_rgbtoxyz (const Babl *space)
+const double * babl_space_get_rgbtoxyz (const Babl *space)
 {
   return space->space.RGBtoXYZ;
 }
index e24640effd59db8f035d9833c118387d8d7ca223..b635c001af6829368c30dc3e98a6c3ee07390414 100644 (file)
@@ -122,7 +122,7 @@ const Babl * babl_space_rgb_chromaticities (const char *name,
                                             const Babl *trc_green,
                                             const Babl *trc_blue);
 
-double * babl_space_get_rgbtoxyz (const Babl *space);
+const double * babl_space_get_rgbtoxyz (const Babl *space);
 void babl_space_to_xyz   (const Babl *space, const double *rgb, double *xyz);
 void babl_space_from_xyz (const Babl *space, const double *xyz, double *rgb);